var $step1 = $(".forget-pwd .find-account");
var $step2 = $(".forget-pwd .send-email");
var $step3 = $(".forget-pwd .pick-new");
var $sign1 = $(".sign1");
var $popWindow = $(".pop-window");
var $sendEmail = $(".sign .send-email");
var $login = $(".login");
var $thirdSign = $(".third-sign");
var $changePwd = $(".change-pwd");
function init(){
	if(isMobile){
		$sign1.find(".all-tip").removeClass("hidden");
		$step1.find(".all-tip").removeClass("hidden");
		$step3.find(".all-tip").removeClass("hidden");
		$thirdSign.find(".all-tip").removeClass("hidden");
		$changePwd.find(".all-tip").removeClass("hidden");
	}
}
init();
//验证
var verification = {
	errorInfo:{
		"1":"You have enter an invalid username or password, please try again.",
		"2":"Your email address is invalid, please correct and try again.",
		"3":"invalid password.",
		"4":"Password is not the same.",
		"5":"error",
		"6":"invalid email"
	},
	email:function(email){
		var reg = /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,6}$/;
		if(reg.test(email)){
			return true;
		}else{
			return false;
		}
	},
	password:function(password){
		var reg = /([0-9][a-zA-Z])|[a-zA-Z]([0-9])/;
		var reg2 = /^[0-9a-zA-Z]*$/g;
		if(reg.test(password) && password.length>=6 && password.length<=20 && reg2.test(password)){
			return true;
		}else{
			return false;
		}
	},
	confirmPassword:function(password,confirmPassword){
		return password==confirmPassword;
	}
}
//初始化
$popWindow.find(".close").on("click",function(){
	$(this).parents(".pop-window").addClass("hide");
	$(this).parents(".window-content").addClass("hide");	
	$sign1.removeClass("hide");
	!$sendEmail.hasClass("hide") && $sendEmail.addClass("hide");
	$step1.removeClass("hide");
	!$step2.hasClass("hide") && $step2.addClass("hide");
	!$step3.hasClass("hide") && $step3.addClass("hide");
	$("html").removeClass("fixation");
	!isMobile && $(this).parents(".window-content").find(".all-tip").addClass("hidden");
	$(this).parents(".window-content").find(".all-tip i").text("");
	$(this).parents(".window-content").find(".tip").text("");
	$(this).parents(".window-content").find(".item").removeClass("error");
})
$popWindow.find(".item input").on("focus",function(){
	$(this).parents(".item").addClass("focus").siblings(".item").removeClass("focus");
})
$popWindow.find(".item input").on("blur",function(){
	$(this).parents(".item").removeClass("focus");
})
$popWindow.find(".log-in").on("click",function(){
	$(".login").removeClass("hide");
	$(".sign").addClass("hide");
})
$popWindow.find(".create a").on("click",function(){
	$(".login").addClass("hide");
	$(".sign").removeClass("hide");
})
$popWindow.find(".forget a").on("click",function(){
	$(".login").addClass("hide");
	$(".forget-pwd").removeClass("hide");
})
//登录--start
$popWindow.find(".login-operation").on("click",function(){
	$login.find(".item").removeClass("error");
	$login.find(".tip").text("");
	$login.find(".all-tip i").text("");

	var pwd = $(".login").find("input[name='password']").val();
	if(!verification.email($(".login").find("input[name='email']").val())){
		$login.find(".tip:nth-of-type(1)").text(verification.errorInfo[6]);
		$login.find(".all-tip i").text(verification.errorInfo[6]);
		$login.find(".item:nth-of-type(1)").addClass("error");
		return;
	} 
	if(!verification.password(pwd)){
		$login.find(".tip:nth-of-type(2)").text(verification.errorInfo[3]);
		$login.find(".all-tip i").text(verification.errorInfo[3]);
		$login.find(".item:nth-of-type(2)").addClass("error");
		return;	
	} 
	$login.find(".all-tip").removeClass("hidden").find("i").text(verification.errorInfo[5]);
	//初始化
	$(".login").find("input[name='email']").val("");
	$(".login").find("input[name='password']").val("");
})
//登录--end
//忘记密码--start 
$step1.find("input[type='submit']").on("click",function(){
	$step1.find(".item").removeClass("error");
	$step1.find(".tip").text("");
	$step1.find(".all-tip i").text("");
	if(!verification.email($step1.find("input[name='email']").val())){
		$step1.find(".tip:nth-of-type(1)").text(verification.errorInfo[6]);
		$step1.find(".all-tip i").text(verification.errorInfo[6]);		
		$step1.find(".item:nth-of-type(1)").addClass("error");
		return;
	} 
	$step1.find(".all-tip").removeClass("hidden").find("i").text(verification.errorInfo[5]);	
	$step1.addClass("hide");
	$step2.removeClass("hide");
})
$step2.find("input[type='button']").on("click",function(){
	$step2.addClass("hide");
	$step3.removeClass("hide");
})
$step3.find(".pick-operation").on("click",function(){
	$step3.find(".item").removeClass("error");
	$step3.find(".tip").text("");
	$step3.find(".all-tip i").text("");
	var pwd = $step3.find("input[name='password']").val();
	if(!verification.password(pwd)){
		$step3.find(".tip:nth-of-type(1)").text(verification.errorInfo[3]);
		$step3.find(".all-tip i").text(verification.errorInfo[3]);		
		$step3.find(".item:nth-of-type(1)").addClass("error");
		return;	
	} 
	if(!verification.confirmPassword(pwd,$step3.find("input[name='confirm']").val())){
		$step3.find(".tip:nth-of-type(2)").text(verification.errorInfo[4]);
		$step3.find(".all-tip i").text(verification.errorInfo[4]);	
		$step3.find(".item:nth-of-type(2)").addClass("error");
		return;		
	} 
	$step3.find(".all-tip").removeClass("hidden").find("i").text(verification.errorInfo[5]);	
})
//忘记密码--end
//修改密码
$changePwd.find("input[type='submit']").on("click",function(){
	$changePwd.find(".item").removeClass("error");
	$changePwd.find(".tip").text("");
	$changePwd.find(".all-tip i").text("");
	var pwd1 = $changePwd.find("input[name='currentPassword']").val();
	var pwd2 = $changePwd.find("input[name='password']").val();

	if(!verification.password(pwd1)){
		$changePwd.find(".tip:nth-of-type(1)").text(verification.errorInfo[3]);
		$changePwd.find(".all-tip i").text(verification.errorInfo[3]);		
		$changePwd.find(".item:nth-of-type(1)").addClass("error");
		return;	
	} 
	if(!verification.password(pwd2)){
		$changePwd.find(".tip:nth-of-type(2)").text(verification.errorInfo[3]);
		$changePwd.find(".all-tip i").text(verification.errorInfo[3]);		
		$changePwd.find(".item:nth-of-type(2)").addClass("error");
		return;	
	} 
	if(!verification.confirmPassword(pwd2,$changePwd.find("input[name='confirm']").val())){
		$changePwd.find(".tip:nth-of-type(3)").text(verification.errorInfo[4]);
		$changePwd.find(".all-tip i").text(verification.errorInfo[4]);	
		$changePwd.find(".item:nth-of-type(3)").addClass("error");
		return;		
	} 
	$changePwd.find(".all-tip").removeClass("hidden").find("i").text(verification.errorInfo[5]);	
})
//
//注册--start
$popWindow.find(".sign-operation").on("click",function(){
	$sign1.find(".item").removeClass("error");
	$sign1.find(".tip").text("");
	$sign1.find(".all-tip i").text("");
	var pwd = $(".sign1 input[name='password']").val();
	if(!verification.email($(".sign1 input[name='email']").val())){
		$sign1.find(".tip:nth-of-type(1)").text(verification.errorInfo[6]);
		$sign1.find(".all-tip i").text(verification.errorInfo[6]);
		$sign1.find(".item:nth-of-type(1)").addClass("error");
		return;
	} 
	if(!verification.password(pwd)){
		$sign1.find(".tip:nth-of-type(2)").text(verification.errorInfo[3]);
		$sign1.find(".all-tip i").text(verification.errorInfo[3]);
		$sign1.find(".item:nth-of-type(2)").addClass("error");
		return;	
	} 
	if(!verification.confirmPassword(pwd,$(".sign1 input[name='confirm']").val())){
		$sign1.find(".tip:nth-of-type(3)").text(verification.errorInfo[4]);
		$sign1.find(".all-tip i").text(verification.errorInfo[4]);
		$sign1.find(".item:nth-of-type(3)").addClass("error");
		return;		
	} 
	$sign1.find(".all-tip").removeClass("hidden").find("i").text(verification.errorInfo[5]);
	$sign1.addClass("hide");
	$sendEmail.removeClass("hide");
	//初始化
	$sign1.find("input[name='email']").val("");
	$sign1.find("input[name='password']").val("");
	$sign1.find("input[name='confirm']").val("");
})
//注册--end
//
//第三方--start
$popWindow.find(".other-login li").on("click",function(){
	$(".login").addClass("hide");
	$(".third-sign").removeClass("hide").find(".item input").each(function(i,item){
		if($(item).val()){
			$(item).parents(".item").addClass("full-value");
		}
	})
})
$thirdSign.find(".third-operation").on("click",function(){
	$thirdSign.find(".item").removeClass("error");
	$thirdSign.find(".tip").text("");
	$thirdSign.find(".all-tip i").text("");

	var pwd = $thirdSign.find("input[name='password']").val();
	if(!verification.email($thirdSign.find("input[name='email']").val())){
		$thirdSign.find(".tip:nth-of-type(1)").text(verification.errorInfo[6]);
		$thirdSign.find(".all-tip i").text(verification.errorInfo[6]);
		$thirdSign.find(".item:nth-of-type(1)").addClass("error");
		return;
	} 
	if(!verification.password(pwd)){
		$thirdSign.find(".tip:nth-of-type(2)").text(verification.errorInfo[3]);
		$thirdSign.find(".all-tip i").text(verification.errorInfo[3]);

		$thirdSign.find(".item:nth-of-type(2)").addClass("error");
		return;	
	} 
	if(!verification.confirmPassword(pwd,$thirdSign.find("input[name='confirm']").val())){
		$thirdSign.find(".tip:nth-of-type(3)").text(verification.errorInfo[4]);
		$thirdSign.find(".all-tip i").text(verification.errorInfo[4]);
		$thirdSign.find(".item:nth-of-type(3)").addClass("error");
		return;		
	} 
	$thirdSign.find(".all-tip").removeClass("hidden").find("i").text(verification.errorInfo[5]);
})
//第三方--end
//
//menu--start
$(".log-menu").on("click",".log-in",function(){
	$("html").addClass("fixation");
	$popWindow.removeClass("hide").find(".login").removeClass("hide");
})
$(".log-menu").on("click",".sign-up",function(){
	$("html").addClass("fixation");
	$popWindow.removeClass("hide").find(".sign").removeClass("hide");
})